Per lavorare con la personalizzazione delle stampe tramite scripting basta settare l'opzione nella ReportsX del layout di stampa del programma desiderato 'Scripting = 0/-1', utilizzata per attivare o meno il motore di script in fase di stampa. Ad esempio nel caso volessimo settare l'attivazione dello scripting per il programma delle forme di pagamento imposteremo: Il motore di script viene caricato nella ReportPeInit, quindi ogni volta che viene lanciata una stampa. Tale motore usa il file BE__CRPE.NTS che deve essere presente nella script del server (esattamente come per gli altri file di script). Impostando ad esempio il seguente codice all'interno del file BE__CRPE: <nts> <reference assembly="BD__BASE.dll" />
<scriptCode><![CDATA[
Imports Microsoft.VisualBasic Imports System Imports System.Collections.Generic Imports System.Data Imports NTSInformatica.CLN__STD Imports NTSInformatica Imports NTSInformatica.CLD__BASE Imports System.IO
Public Class BE__CRPEVBS Implements INT__SCRIPT
Dim oCldBase As CLD__BASE Dim fErr As StreamWriter = Nothing Dim fiErr As FileInfo = Nothing Dim strNomeFileLog As String = ""
Public Function Exec(ByVal strCommand As String, ByRef oApp As Object, _ ByRef oIn As Object, _ ByRef oParam As Object) As Object Implements INT__SCRIPT.Exec '------------------------------------ 'PARAMETRI PASSATI DAL CHIAMANTE Dim arParam As New List(Of Object) 'arParam.Add(oFrmParent) 'arParam.Add(strkey1) 'arParam.Add(strkey2) 'arParam.Add(nIndex) 'arParam.Add(strTipoDoc) 'arParam.Add(bDefault) '------------------------------------ Try strNomeFileLog = oApp.ServerDir & "\Script\BE__CRPE.LOG" fiErr = New FileInfo(strNomeFileLog) If fiErr.Exists Then If fiErr.Length > 500000 Then fiErr.Delete() End If fErr = New StreamWriter(strNomeFileLog, True) fErr.Write(strCommand & vbCrLf) fErr.Flush() fErr.Close()
oCldBase = New CLD__BASE oCldBase.Init(oApp)
arParam = oIn
Select Case strCommand.ToUpper() 'Case "template_ReportSelectedCond".ToUpper() ' Return template_ReportSelectedCond(CType(arParam(4), String), oApp) 'Case "template_ReportNameCond".ToUpper() ' Return template_ReportNameCond(CType(arParam(4), String), oApp) 'Case "template_PrinterNameCond".ToUpper() ' Return template_PrinterNameCond(CType(arParam(4), String), oApp) 'Case "template_ScriptPrint".ToUpper() ' Return template_ScriptPrint(CType(arParam(4), String), oApp) 'Case "template_PaperSizeCond".ToUpper() ' Return template_PaperSizeCond(CType(arParam(4), String), oApp) 'Case "template_CopiesCond".ToUpper() ' Return template_CopiesCond(CType(arParam(4), String), oApp) End Select
Return Nothing
Catch ex As Exception Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) Return Nothing End Try End Function
'Private Function template_ReportSelectedCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
'Private Function template_ReportNameCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
'Private Function template_PrinterNameCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
'Private Function template_ScriptPrint(ByVal strTipoDoc As String, ByRef oApp As Object) As Boolean ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
'Private Function template_PaperSizeCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
'Private Function template_CopiesCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception ' Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) ' Return Nothing ' End Try 'End Function
End Class
]]></scriptCode> </nts>
Noteremo che rilanciando la stampa del repor delle forme di pagamento, se abbiamo impostato lo script precedente in BE__CRPE, verrą prodotto il seguente file di LOG: Possiamo di voler usare uno degli eventi indicati (BS--PAGA_Reports1_Rep1_PrinterNameCond) per impostare ad esempio un certo nome di stampante, nel codice precedente aggiungeremo un case compiando l'evento voluto dal file di LOG: ' Return template_PaperSizeCond(CType(arParam(4), String), oApp) 'Case "template_ScriptPrint".ToUpper() ' Return template_ScriptPrint(CType(arParam(4), String), oApp) Case "BS--PAGA_Reports1_Rep1_PrinterNameCond".ToUpper() Return BS__PAGA_Reports1_Rep1_PrinterNameCond(CType(arParam(4), String), oApp) End Select
Return Nothing
Catch ex As Exception Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) Return Nothing End Try End Function
Private Function BS__PAGA_Reports1_Rep1_PrinterNameCond(ByVal strTipoDoc As String, _
ByRef oApp As Object) As String Try Return "PDF995" Catch ex As Exception Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) Return Nothing End Try End Function
'Private Function template_ReportSelectedCond(ByVal strTipoDoc As String, ByRef oApp As Object) As String ' Try ' Return Nothing ' Catch ex As Exception
Esempio di conversione di una funzione da scripting vb6 (supportato dal precedente classic start) a script .NET Scripting vb6: ReportSelectedCond=Function ReportSelectedCond() Dim strSQL, snaTest ReportSelectedCond = False strSQL = "SELECT Count(*) " & _ "FROM movmag " & _ "WHERE mm_tipork = '" & fmOwner.strTmTipork & "' " & _ "AND mm_anno = " & fmOwner.nTmAnno & " " & _ "AND mm_serie = '" & fmOwner.strTmSerie & "' " & _ "AND mm_numdoc = " & fmOwner.lTmNumdoc & " " & _ "AND Ucase(Mid(mm_codart, 1, 3)) = 'MOC'" If gstrSubDataType = "(Nessuno)" Then Set snaTest = gdb.OpenRecordset(strSQL, 4) Else Set snaTest = gcn.OpenRecordset(strSQL, 4) End If If Not snaTest.EOF Then If Not IsNull(snaTest(0)) Then If snaTest(0) > 0 Then ReportSelectedCond = True End if End If snaTest.Close Set snaTest = Nothing End Function [#A]
Script .NET: Select Case strCommand.ToUpper() Case "BSVEBOLL_Reports1_Rep3_ReportSelectedCond".ToUpper() Return BSVEBOLL_Reports1_Rep3_ReportSelectedCond(CType(arParam(4), String), arParam(0), _ CType(arParam(5), String), oApp) End Select
Return Nothing Catch ex As Exception Dim strErr As String = CLN__STD.GestError(ex, Nothing, "", oApp.InfoError, oApp.ErrorLogFile, True) Return Nothing End Try End Function
Private Function BSVEBOLL_Reports1_Rep3_ReportSelectedCond(ByVal strTipoDoc As String, _ ByVal oFrmParent As Object, _ ByVal oDefault As String, _ ByRef oApp As Object) As String Dim strSQL As String = "" Try If strTipoDoc.ToUpper = "A" Then If Not oFrmParent Is Nothing Then If oFrmParent.Name = "FRMVEBOLL" Then strSQL = "SELECT *" & _ "FROM movmag " & _ "WHERE mm_tipork = '" & oFrmParent.cbTipoDoc.SelectedValue & "' " & _ "AND mm_anno = " & oFrmParent.edAnnoDoc.Text & " " & _ "AND mm_serie = '" & oFrmParent.edSerieDoc.Text & "' " & _ "AND mm_numdoc = " & oFrmParent.edNumDoc.Text & " " & _ "AND UPPER(substring(mm_codart, 1, 3)) = 'MOC'" Dim dttTest As New DataTable dttTest = oCldBase.OpenRecordset(strSQL, CLE__APP.DBTIPO.DBAZI) If Not dttTest Is Nothing AndAlso _ dttTest.Rows.Count > 0 Then Return "-1" End If End If End If End If Return "0" Catch ex As Exception Dim strErr As String = CLN__STD.GestError(ex, Nothing, strSQL, oApp.InfoError, _ oApp.ErrorLogFile, True) Return "0" End Try End Function
Per ulteriori informazioni sulla realizzazione delle personalizzazioni tramite script consultare l'apposita circolare tecnica. |